package routes

import (
	"go-api-demo/controllers"
	"go-api-demo/middleware"

	"github.com/gin-gonic/gin"

	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

func SetupRouter() *gin.Engine {
	r := gin.Default()

	// ✅ Swagger UI 路由
	r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	
	// 确保图片路径可访问
	r.Static("/uploads", "./uploads")

	api := r.Group("/api/v1")
	{
		// 公共接口
		api.POST("/upload", controllers.UploadFile)
		api.POST("/register", controllers.Register)
		api.POST("/login", controllers.Login)

		

		// 受保护接口（JWT 中间件）
		auth := api.Group("/")
		auth.Use(middleware.JWTAuth())
		{
			auth.GET("/profile", controllers.Profile)
			auth.PUT("/profile", controllers.UpdateProfile)
			auth.DELETE("/profile", controllers.DeleteAccount)
		}
	}

	return r
}
